﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using MementoClient.Interfaces;

namespace MementoClient.Logging
{
    public class Logger : ILogger
    {
        public void Info(string message)
        {
            MessageBoxResult result = MessageBox.Show(message);
        }

        public void Warn(string message)
        {
            MessageBoxResult result = MessageBox.Show(message);
        }

        public void Debug(string message)
        {
            MessageBoxResult result = MessageBox.Show(message);
        }

        public void Error(string message)
        {
            MessageBoxResult result = MessageBox.Show(message);
        }

        public void Error(Exception x)
        {
            MessageBoxResult result = MessageBox.Show(this.BuildExceptionMessage(x));
        }

        public void Fatal(string message)
        {
            MessageBoxResult result = MessageBox.Show(message);
        }

        public void Fatal(Exception x)
        {
            MessageBoxResult result = MessageBox.Show(this.BuildExceptionMessage(x));
        }

        private string BuildExceptionMessage(Exception x)
        {
            Exception logException = x;
            if (x.InnerException != null)
                logException = x.InnerException;

            string strErrorMsg = Environment.NewLine + "Message :" + logException.Message;

            strErrorMsg += Environment.NewLine + "Source :" + logException.Source;

            strErrorMsg += Environment.NewLine + "Stack Trace :" + logException.StackTrace;

            strErrorMsg += Environment.NewLine + "TargetSite :" + logException.TargetSite;
            return strErrorMsg;
        }
    }
}
